#!/bin/bash

#------------------------
#@title mysql5.6.28安装
#@description  
#@author xcheng1986@126.com
#@date 2016-03-30
#------------------------

#1.追加CentOS 6.5的epel及remi源。
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

#2.工具包安装
yum -y update
yum -y install wget patch make cmake gcc gcc-c++ gcc-g77 perl flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils libcurl-devel libmcrypt-devel libedit libedit-devel readline readline-devel  pcre pcre-devel

#安装上传下载工具
wget -c http://www.lixiaocheng.com/editor/attached/file/20160308/szrz.sh && sh szrz.sh

#3.mysql安装

wget -c http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
tar -xzvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./bootstrap
make && make install
cd ..

groupadd mysql ; useradd -r -g mysql mysql
mkdir -p /usr/local/mysql ; mkdir -p /data/mysqldb

wget -c http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.28.tar.gz
tar zxvf mysql-5.6.28.tar.gz
cd mysql-5.6.28
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1  
rm -rf CMakeCache.txt
make
make install

cd /usr/local/mysql
chown -R mysql:mysql .
cd /data/mysqldb
chown -R mysql:mysql .
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
\cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

sed -i 's;# basedir = .....;basedir = /usr/local/mysql/;g' /etc/my.cnf
sed -i 's;# datadir = .....;datadir = /data/mysqldb;g' /etc/my.cnf
sed -i 's;# port = .....;port = 3306;g' /etc/my.cnf
sed -i 's;# server_id = .....;server_id = 1;g' /etc/my.cnf
sed -i 's;# socket = .....;socket = /usr/local/mysql/mysql.sock;g' /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

echo '#Mysql环境变量' >> /etc/profile ;
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile ;
echo 'export PATH' >> /etc/profile ;
source /etc/profile

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql             ;
ln -s /usr/local/mysql/include/mysql /usr/include/mysql     ;
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql             ;
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump     ;
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk     ;
ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe 

service mysqld start
chkconfig --level 35 mysqld on
netstat -tulnp | grep 3306
ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
mysqladmin -u root password '123456'

#mysql -u root -p123456
#(密码123456)
#mysql> show databases;
#mysql> \q

cd ..
